<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        借还流水
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">

</head>
<!--借还流水-->
<style>
    .layui-form-label {
        width: 150px !important;
    }
</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="hkrq"> <span class='x-red'>*</span>还款日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" id="repaymentDate" name="repaymentDate"
                               v-model="borrowAndReturnWater.repaymentDate"
                               lay-verify="required" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="hkje"> <span class='x-red'>*</span>还款金额</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="repaymentAmount"
                               v-model="borrowAndReturnWater.repaymentAmount"
                               lay-verify="required" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>款项类型</label>
                    <div class="layui-input-inline">
                        <select name="typeOfPayment" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>收支途径</label>
                    <div class="layui-input-inline">
                        <select name="revenueAndExpenditureChannels" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="hkdw"> <span class='x-red'></span>还款单位</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="repaymentUnit" v-model="borrowAndReturnWater.repaymentUnit"
                               placeholder="请输入" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="jkrq"> <span class='x-red'></span>借款日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" id="dateOfLoan" name="dateOfLoan"
                               v-model="borrowAndReturnWater.dateOfLoan"
                               placeholder="请输入" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>资金账户</label>
                    <div class="layui-input-inline">
                        <select name="capitalAccount" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>关联项目</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="relatedApproval" v-model="borrowAndReturnWater.relatedApproval"
                               placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>摘要备注</label>
                    <div style="width: 70%" class="layui-input-inline">
                         <textarea name="remark" placeholder="请输入内容" v-model="borrowAndReturnWater.remark"
                                   class="layui-textarea"></textarea>
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <!--</form>-->
                <div style="height:20px;"></div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })
</script>
<script>

    var recordId = getQueryVariable("recordId");
    var type = getQueryVariable("type");

    if (type === 'jk') {
        $("#hkrq").text('借款日期');
        $("#hkje").text('借款金额');
        $("#hkdw").text('出借单位');
        $("#jkrq").text('计划还款');

    }

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;

            laydate.render({
                elem: '#repaymentDate', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.borrowAndReturnWater.repaymentDate = value
                }
            });
            laydate.render({
                elem: '#dateOfLoan', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.borrowAndReturnWater.dateOfLoan = value
                }
            });

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.addUserId = $userId;
                    form.id = vm.borrowAndReturnWater.id;
                    vm.borrowAndReturnWater.id == null ? form.operationType = 'add' : form.operationType = 'edit';
                    type === 'jk' ? form.type = '借款' : form.type = '还款';
                    form.capitalAccountId = form.capitalAccount;
                    form.capitalAccount = $("select[name=capitalAccount]").find("option:selected").text()


                    let request = {
                        url: 'borrowAndReturnWater/addBorrowAndReturnWater',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });


        });


    const vm = new Vue({
        el: "#app",
        data: {
            borrowAndReturnWater: {
                id: null,
                repaymentDate: null,
                repaymentAmount: null,
                typeOfPayment: null,
                revenueAndExpenditureChannels: null,
                repaymentUnit: null,
                dateOfLoan: null,
                capitalAccount: null,
                capitalAccountId: null,
                relatedApproval: null,
                relatedApprovalId: null,
                type: null,
                remark: null,
                addUserId: null,
            }
        },
        created() {

            if (recordId) {
                let request = {
                    url: 'borrowAndReturnWater/findBorrowAndReturnWaterList',
                    data: {
                        userId: $userId,
                        recordId: recordId
                    },
                    method: "POST"
                }
                sendRequest(request, (res) => {
                    // console.log(res);
                    this.borrowAndReturnWater = res.data;
                })
            }

        },
        computed: {},
        methods: {},


    });

    setTimeout(() => {
        //修改状态
        let form = layui.form;
        //收支途径
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'REVENUE_AND_EXPENDITURE_CHANNEL'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=revenueAndExpenditureChannels]").append(opt);

            });

            $("select[name=revenueAndExpenditureChannels]").val(vm.borrowAndReturnWater.revenueAndExpenditureChannels);

            form.render('select');
        });
        //款项类型
        let request3 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'TYPE_OF_PAYMENT'
            },
            method: "POST",
        };
        sendRequest(request3, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=typeOfPayment]").append(opt);
            });

            $("select[name=typeOfPayment]").val(vm.borrowAndReturnWater.typeOfPayment);

            form.render('select');
        });

        //账户名称
        let request2 = {
            url: 'companyAccount/findCompanyAccountSelect',
            data: {
                userId: $userId,
            },
            method: "POST",
        };
        sendRequest(request2, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item.id + ">" + item.accountName + "</option>");
                $("select[name=capitalAccount]").append(opt);

            });

            $("select[name=capitalAccount]").val(vm.borrowAndReturnWater.capitalAccount);

            form.render('select');
        });
    }, 300)

</script>

</body>

</html>
